﻿// Decompiled by AS3 Sorcerer 6.12
// www.as3sorcerer.com

//Cell

package 
{
    import flash.display.Sprite;
    import com.gamezhero.api.as3.GamezheroDictionary;
    import flash.events.Event;
    import flash.display.Graphics;
    import com.gamezhero.api.as3.*;
    import flash.events.*;

    public class Cell extends Sprite 
    {

        public static const MIN_PANIC_POWER:int = 5;
        public static const MIN_ATTACK_POWER:int = 5;
        private static const GREY_GIVE_UP_DIV:int = 3;
        private static const MAX_POWER_CREDIT:int = 0;
        public static const TYPE_GREY:int = 1;
        public static const TYPE_RED:int = 2;
        public static const TYPE_GREEN:int = 3;
        public static const TYPE_BLACK:int = 4;
        public static const TYPE_PURPLE:int = 5;

        private const _SafeStr_104:int = 18;

        private var m_game:Level;
        private var _SafeStr_90:uint = 0;
        private var _SafeStr_91:Boolean = false;
        private var _SafeStr_92:int = 0;
        private var _SafeStr_84:int = 0;
        private var _SafeStr_89:Array = null;
        private var _SafeStr_94:Sprite = null;
        private var _SafeStr_98:Array = null;
        private var _SafeStr_103:Number = 0;
        private var _SafeStr_100:int = 1;
        private var _SafeStr_105:uint = 0;
        private var _SafeStr_101:Pulsar = null;
        private var _SafeStr_86:Sfx = null;
        private var _SafeStr_107:Number = 0;
        private var _SafeStr_87:Array = null;
        private var _SafeStr_83:int = 0;
        private var _SafeStr_97:Boolean = false;
        private var _SafeStr_111:uint = 0;
        private var _SafeStr_110:uint = 20;
        private var _SafeStr_95:int = 0;
        private var _SafeStr_85:Sprite = null;
        private var _SafeStr_96:Array = null;
        private var _SafeStr_112:uint = 2;
        private var _SafeStr_113:uint = 20;
        private var _SafeStr_109:uint = 0;
        private var _SafeStr_99:int = 0;
        private var _SafeStr_88:int = 0;

        public function Cell(game:Level, _arg_2:int, initPower:int, maxPower:int=999)
        {
            this.m_game = game;
            this._SafeStr_95 = _arg_2;
            this._SafeStr_83 = initPower;
            this._SafeStr_84 = maxPower;
            this._SafeStr_89 = new Array();
            this._SafeStr_98 = new Array();
            this._SafeStr_96 = new Array();
            this._SafeStr_87 = new Array();
            this._SafeStr_86 = new Sfx();
            this._SafeStr_85 = new Sprite();
            this._SafeStr_88 = 0;
            if (this._SafeStr_83 > this._SafeStr_84)
            {
                this._SafeStr_83 = this._SafeStr_84;
            };
            this._SafeStr_85.mouseEnabled = false;
            this._SafeStr_85.mouseChildren = false;
            addChild(this._SafeStr_86);
            addChild(this._SafeStr_85);
            this._SafeStr_87[0] = new EvoInfo(15, CellNode.TYPE1, -1, 0, 40, 30, GamezheroDictionary.getTranslationByName("spore").toLocaleUpperCase(), 1);
            this._SafeStr_87[CellNode.TYPE1] = new EvoInfo(40, CellNode.TYPE2, 5, 0, 45, 20, GamezheroDictionary.getTranslationByName("embryo").toLocaleUpperCase(), 2);
            this._SafeStr_87[CellNode.TYPE2] = new EvoInfo(80, CellNode.TYPE3, 30, CellNode.TYPE1, 50, 15, (GamezheroDictionary.getTranslationByName("pulsar").toLocaleUpperCase() + "-A"), 2);
            this._SafeStr_87[CellNode.TYPE3] = new EvoInfo(120, CellNode.TYPE4, 60, CellNode.TYPE2, 60, 10, (GamezheroDictionary.getTranslationByName("pulsar").toLocaleUpperCase() + "-B"), 2);
            this._SafeStr_87[CellNode.TYPE4] = new EvoInfo(160, CellNode.TYPE5, 100, CellNode.TYPE3, 80, 5, GamezheroDictionary.getTranslationByName("ant").toLocaleUpperCase(), 3);
            this._SafeStr_87[CellNode.TYPE5] = new EvoInfo(210, CellNode.TYPE5, 140, CellNode.TYPE4, 100, 2, GamezheroDictionary.getTranslationByName("predator").toLocaleUpperCase(), 3);
            do 
            {
            } while (this._SafeStr_106());
            this._SafeStr_93();
            addEventListener(Event.ENTER_FRAME, this.onEnterFrame);
        }

        public function get maxPower():int
        {
            return (this._SafeStr_84);
        }

        public function set maxPower(value:int):void
        {
            this._SafeStr_84 = value;
            if (this._SafeStr_83 > this._SafeStr_84)
            {
                this._SafeStr_83 = this._SafeStr_84;
                do 
                {
                } while (this._SafeStr_106());
                this._SafeStr_93();
            };
        }

        public function get maxOrigLinks():int
        {
            var info:EvoInfo = this._SafeStr_87[this._SafeStr_88];
            return (info.maxLinks);
        }

        public function get power():int
        {
            return (this._SafeStr_83);
        }

        public function getAnchorTo(cell:Cell):Anchor
        {
            var ang:Number;
            var STEP:int = 10;
            var dx:Number = (cell.x - this.x);
            var dy:Number = (cell.y - this.y);
            var dir:Number = ((Math.atan2(dy, dx) * 180) / Math.PI);
            if (dir < 0)
            {
                dir = (360 + dir);
            };
            var index:int = int((dir / STEP));
            var anchor:Anchor = this._SafeStr_89[index];
            var radius:Number = this.radius();
            if (anchor == null)
            {
                ang = (((index * STEP) * Math.PI) / 180);
                anchor = new Anchor((x + (Math.cos(ang) * radius)), (y + (Math.sin(ang) * radius)));
                this._SafeStr_89[index] = anchor;
            };
            return (anchor);
        }

        public function set power(value:int):void
        {
            if (value > this._SafeStr_84)
            {
                value = this._SafeStr_84;
            };
            this._SafeStr_83 = value;
            do 
            {
            } while (this._SafeStr_106());
            this._SafeStr_93();
        }

        public function addImpulse(dir:Number, value:Number=1):void
        {
            var rad:Number = ((dir * Math.PI) / 180);
            var mass:Number = (this._SafeStr_83 / 20);
            if (mass < 1)
            {
                mass = 1;
            };
        }

        private function _SafeStr_93():void
        {
            var step:Number;
            var begin:Number;
            var node:CellNode;
            var color:uint = GUI.OUTLINE_COLOR;
            var bgcolor:uint = GUI.INNER_COLOR;
            var centerColor:uint = this.baseColor();
            var g:Graphics = this._SafeStr_85.graphics;
            g.clear();
            g.lineStyle(2, color);
            g.beginFill(bgcolor, 0.3);
            g.drawCircle(0, 0, this.radius());
            g.endFill();
            g.lineStyle(2, color);
            g.beginFill(centerColor, ((this._SafeStr_83 < MIN_ATTACK_POWER) ? (this._SafeStr_83 / MIN_ATTACK_POWER) : 1));
            g.drawCircle(0, 0, 15);
            g.endFill();
            if (this._SafeStr_94)
            {
                this._SafeStr_85.removeChild(this._SafeStr_94);
                this._SafeStr_94 = null;
            };
            var i:int;
            if (this._SafeStr_95 != TYPE_GREY)
            {
                this._SafeStr_94 = GUI.createText(("" + this._SafeStr_83), 15, 0xFFFFFF);
                this._SafeStr_94.y = -3;
                this._SafeStr_85.addChild(this._SafeStr_94);
                step = 5;
                begin = (-((this.maxOrigLinks * step) / 2) + (step / 2));
                g.lineStyle(1, color);
                i = 0;
                while (i < this.maxOrigLinks)
                {
                    g.beginFill(((i >= this.numOrigLinks) ? 0xAAAAAA : 0));
                    g.drawCircle((begin + (i * step)), 7, 2.5);
                    g.endFill();
                    i++;
                };
            };
            this._SafeStr_106();
            this._SafeStr_114();
            i = 0;
            while (i < this._SafeStr_96.length)
            {
                node = this._SafeStr_96[i];
                node.setRadius(this.radius());
                i++;
            };
        }

        public function destruct():void
        {
            var link:Link;
            if (!this._SafeStr_97)
            {
                removeEventListener(Event.ENTER_FRAME, this.onEnterFrame);
            };
            while (this._SafeStr_98.length > 0)
            {
                link = this._SafeStr_98.pop();
                link.destruct();
            };
            this._SafeStr_116();
            this.m_game.delCell(this);
        }

        public function getOccupantPower():int
        {
            return (this._SafeStr_99);
        }

        public function receiveAttack(_arg_1:int, amount:uint):void
        {
            var _local_4:int;
            var captured:Boolean;
            if (_arg_1 != this._SafeStr_95)
            {
                if (this._SafeStr_95 != TYPE_GREY)
                {
                    this._SafeStr_83 = (this._SafeStr_83 - amount);
                    if (this._SafeStr_83 <= 0)
                    {
                        this._SafeStr_83 = 10;
                        captured = true;
                    };
                }
                else
                {
                    this._SafeStr_99 = (this._SafeStr_99 + ((this._SafeStr_100 == _arg_1) ? amount : -(amount)));
                    if (this._SafeStr_99 < 0)
                    {
                        this._SafeStr_100 = _arg_1;
                        this._SafeStr_99 = -(this._SafeStr_99);
                        if (this._SafeStr_101)
                        {
                            removeChild(this._SafeStr_101);
                            this._SafeStr_101.destruct();
                            this._SafeStr_101 = null;
                        };
                        this._SafeStr_101 = new Pulsar(0, 0, this.baseColor(_arg_1), 0);
                        addChild(this._SafeStr_101);
                    };
                    _local_4 = int((this._SafeStr_83 / GREY_GIVE_UP_DIV));
                    if (this._SafeStr_99 >= _local_4)
                    {
                        if (this._SafeStr_83 < 10)
                        {
                            this._SafeStr_83 = 10;
                        };
                        captured = true;
                        if (this._SafeStr_101)
                        {
                            removeChild(this._SafeStr_101);
                            this._SafeStr_101.destruct();
                            this._SafeStr_101 = null;
                        };
                    };
                    if (this._SafeStr_101)
                    {
                        this._SafeStr_101.setSize(((this._SafeStr_99 * 10) / _local_4));
                    };
                };
            }
            else
            {
                this._SafeStr_108(amount);
            };
            if (captured)
            {
                this._SafeStr_95 = _arg_1;
                this._SafeStr_88 = 0;
                do 
                {
                } while (this._SafeStr_106());
                this._SafeStr_102();
                this._SafeStr_86.startWave(this.radius());
                SoundMgr.playSfx(SoundMgr.CELL_OCCUPIED);
            };
            this._SafeStr_93();
        }

        private function _SafeStr_102():void
        {
            var tmp:Array = new Array();
            var link:Link;
            var i:int;
            while (i < this._SafeStr_98.length)
            {
                link = this._SafeStr_98[i];
                tmp.push(link);
                i++;
            };
            while (tmp.length > 0)
            {
                link = tmp.pop();
                link.cutAt(1);
            };
        }

        public function get numOrigLinks():int
        {
            return (this._SafeStr_98.length);
        }

        public function getGiveUpPower():int
        {
            return ((this._SafeStr_95 == TYPE_GREY) ? int(((this._SafeStr_83 / GREY_GIVE_UP_DIV) - this._SafeStr_99)) : this._SafeStr_83);
        }

        public function radius():Number
        {
            var r:Number = (this._SafeStr_104 + (this._SafeStr_83 / 10));
            return (r);
        }

        public function delOriginLink(link:Link):void
        {
            var i:int = this._SafeStr_98.indexOf(link);
            if (i >= 0)
            {
                this._SafeStr_98.splice(i, 1);
            };
            this._SafeStr_93();
        }

        public function getName():String
        {
            var color:String;
            var info:EvoInfo = this._SafeStr_87[this._SafeStr_88];
            switch (this._SafeStr_95)
            {
                case TYPE_GREY:
                    color = "";
                    break;
                case TYPE_RED:
                    color = "";
                    break;
                case TYPE_GREEN:
                    color = "";
                    break;
                case TYPE_BLACK:
                    color = "";
                    break;
                case TYPE_PURPLE:
                    color = "";
                    break;
            };
            return (color + info.name);
        }

        private function _SafeStr_106():Boolean
        {
            var i:int;
            var node:CellNode;
            var changed:Boolean;
            var prevEvo:int = this._SafeStr_88;
            var info:EvoInfo = this._SafeStr_87[this._SafeStr_88];
            var power:int = this._SafeStr_83;
            if (power >= info.upgradePower)
            {
                this._SafeStr_88 = info.upgrageType;
            }
            else
            {
                if (power <= info.downgradePower)
                {
                    this._SafeStr_88 = info.downgradeType;
                };
            };
            info = this._SafeStr_87[this._SafeStr_88];
            this._SafeStr_110 = info.growPeriod;
            this._SafeStr_113 = info.attackPeriod;
            if (prevEvo != this._SafeStr_88)
            {
                changed = true;
                this._SafeStr_116();
                if (this._SafeStr_88 != 0)
                {
                    i = 0;
                    while (i < 360)
                    {
                        node = new CellNode(this._SafeStr_88, this.radius(), i, this.baseColor());
                        this._SafeStr_96.push(node);
                        addChild(node);
                        i = (i + 45);
                    };
                };
                this._SafeStr_86.startWave(this.radius());
            };
            if (((this._SafeStr_95 == this.m_game.getUserCellType()) && (this._SafeStr_88 == CellNode.TYPE5)))
            {
                this.m_game.newAchievement(Achievements.ID_TOP_LIFE_FORM);
            };
            return (changed);
        }

        public function baseColor(_arg_1:int=-1):uint
        {
            var color:uint;
            if (_arg_1 == -1)
            {
                _arg_1 = this._SafeStr_95;
            };
            switch (_arg_1)
            {
                case TYPE_GREY:
                    color = 0x888888;
                    break;
                case TYPE_RED:
                    color = 11154227;
                    break;
                case TYPE_GREEN:
                    color = 3385907;
                    break;
                case TYPE_BLACK:
                    color = 0x111111;
                    break;
                case TYPE_PURPLE:
                    color = 11154346;
                    break;
            };
            return (color);
        }

        private function _SafeStr_108(amount:uint=1):void
        {
            if (this._SafeStr_92 > 0)
            {
                this._SafeStr_92 = (this._SafeStr_92 - amount);
                if (this._SafeStr_92 < 0)
                {
                    this._SafeStr_83 = (this._SafeStr_83 - this._SafeStr_92);
                    this._SafeStr_92 = 0;
                };
            }
            else
            {
                this._SafeStr_83++;
            };
            if (this._SafeStr_83 > this._SafeStr_84)
            {
                this._SafeStr_83 = this._SafeStr_84;
            };
            this._SafeStr_93();
        }

        private function onEnterFrame(event:Event):void
        {
            this._SafeStr_115();
            if (this._SafeStr_91)
            {
                return;
            };
            if (this._SafeStr_95 != TYPE_GREY)
            {
                this._SafeStr_111++;
            };
            var growPeriod:int = ((this._SafeStr_109 > 0) ? (this._SafeStr_110 * this._SafeStr_109) : this._SafeStr_110);
            if (this._SafeStr_111 > growPeriod)
            {
                this._SafeStr_111 = 0;
                this._SafeStr_108();
            };
            this._SafeStr_105++;
            if (this._SafeStr_105 > this._SafeStr_112)
            {
                this._SafeStr_105 = 0;
                this._SafeStr_117();
            };
            this._SafeStr_90++;
            if (this._SafeStr_90 > this._SafeStr_113)
            {
                this._SafeStr_90 = 0;
                this.sendAttack();
            };
        }

        public function addOriginLink(link:Link):void
        {
            this._SafeStr_98.push(link);
            this._SafeStr_86.startWave(this.radius());
            this._SafeStr_93();
        }

        public function suspend():void
        {
            var link:Link;
            if (this._SafeStr_91)
            {
                return;
            };
            this._SafeStr_91 = true;
            var i:int;
            while (i < this._SafeStr_98.length)
            {
                link = this._SafeStr_98[i];
                link.cutAt(1);
                i++;
            };
        }

        public function get type():int
        {
            return (this._SafeStr_95);
        }

        public function addMoveDelta(dir:Number, value:Number=1):void
        {
            var rad:Number = ((dir * Math.PI) / 180);
            this._SafeStr_107 = (this._SafeStr_107 + (Math.cos(rad) * value));
            this._SafeStr_103 = (this._SafeStr_103 + (Math.sin(rad) * value));
        }

        private function _SafeStr_114():void
        {
            var anchor:Anchor;
            var ang:Number;
            var i:int;
            while (i <= 36)
            {
                anchor = this._SafeStr_89[i];
                ang = (((i * 10) * Math.PI) / 180);
                if (anchor)
                {
                    anchor.update((x + (Math.cos(ang) * this.radius())), (y + (Math.sin(ang) * this.radius())));
                };
                i++;
            };
        }

        private function _SafeStr_115():void
        {
            this._SafeStr_107 = (this._SafeStr_107 * 0.6);
            this._SafeStr_103 = (this._SafeStr_103 * 0.6);
            x = (x + this._SafeStr_107);
            y = (y + this._SafeStr_103);
            if (((Math.abs(this._SafeStr_107) > 0) || (Math.abs(this._SafeStr_103) > 0)))
            {
                this._SafeStr_114();
            };
        }

        private function _SafeStr_116():void
        {
            var node:CellNode;
            while (this._SafeStr_96.length > 0)
            {
                node = this._SafeStr_96.pop();
                removeChild(node);
                node.destruct();
                node = null;
            };
        }

        private function sendAttack():void
        {
            var link:Link;
            var isUpdateView:Boolean;
            var attacksNum:int;
            var i:int;
            while (i < this._SafeStr_98.length)
            {
                link = this._SafeStr_98[i];
                if (this._SafeStr_83 < MIN_ATTACK_POWER)
                {
                    break;
                };
                if (link.isAttached())
                {
                    if (link.sendAttack(1))
                    {
                        attacksNum++;
                    };
                };
                i++;
            };
            if (this._SafeStr_83 < 0)
            {
                this._SafeStr_83 = 0;
            };
            if (isUpdateView)
            {
                this._SafeStr_93();
            };
            this._SafeStr_109 = (attacksNum * 2);
        }

        public function getAngleTo(cell:Cell):Number
        {
            var dx:Number = (cell.x - this.x);
            var dy:Number = (cell.y - this.y);
            return ((Math.atan2(dy, dx) * 180) / Math.PI);
        }

        public function set type(value:int):void
        {
            var tmpPower:int = this._SafeStr_83;
            this._SafeStr_83 = 1;
            do 
            {
            } while (this._SafeStr_106());
            this._SafeStr_83 = tmpPower;
            this._SafeStr_95 = value;
            do 
            {
            } while (this._SafeStr_106());
            this._SafeStr_93();
        }

        private function _SafeStr_117():void
        {
            var link:Link;
            var isUpdateView:Boolean;
            var i:int;
            while (i < this._SafeStr_98.length)
            {
                link = this._SafeStr_98[i];
                if (!link.isBusy())
                {
                    if (link.addSeg())
                    {
                        if (this._SafeStr_83 > 0)
                        {
                            this._SafeStr_83--;
                        }
                        else
                        {
                            this._SafeStr_92++;
                        };
                        isUpdateView = true;
                    };
                    if (((!(link.isAttached())) && (this._SafeStr_92 > MAX_POWER_CREDIT)))
                    {
                        link.cutAt(1);
                        this._SafeStr_86.startWave(this.radius());
                    };
                };
                i++;
            };
            if (isUpdateView)
            {
                this._SafeStr_93();
            };
        }

        public function pause(enabled:Boolean):void
        {
            if (this._SafeStr_97 == enabled)
            {
                return;
            };
            this._SafeStr_97 = enabled;
            if (this._SafeStr_97)
            {
                removeEventListener(Event.ENTER_FRAME, this.onEnterFrame);
            }
            else
            {
                addEventListener(Event.ENTER_FRAME, this.onEnterFrame);
            };
        }


    }
}//package 

class EvoInfo 
{

    public var attackPeriod:int = 0;
    public var name:String = "";
    public var downgradeType:int = 0;
    public var downgradePower:int = 0;
    public var upgrageType:int = 0;
    public var growPeriod:int = 0;
    public var maxLinks:int = 0;
    public var upgradePower:int = 0;

    public function EvoInfo(upgradePower:int, upgrageType:int, downgradePower:int, downgradeType:int, growPeriod:int, attackPeriod:int, name:String="", maxLinks:int=1)
    {
        this.upgradePower = upgradePower;
        this.upgrageType = upgrageType;
        this.downgradePower = downgradePower;
        this.downgradeType = downgradeType;
        this.growPeriod = growPeriod;
        this.attackPeriod = attackPeriod;
        this.name = name;
        this.maxLinks = maxLinks;
    }

}


// _SafeStr_100 = "_-0s" (String#4693, DoABC#2)
// _SafeStr_101 = "_-3r" (String#4835, DoABC#2)
// _SafeStr_102 = "_-5J" (String#4902, DoABC#2)
// _SafeStr_103 = "_-2c" (String#4779, DoABC#2)
// _SafeStr_104 = " each" (String#3387, DoABC#2)
// _SafeStr_105 = "_-71" (String#4987, DoABC#2)
// _SafeStr_106 = "_-6E" (String#4947, DoABC#2)
// _SafeStr_107 = "_-1N" (String#4718, DoABC#2)
// _SafeStr_108 = "_-01" (String#4656, DoABC#2)
// _SafeStr_109 = "_-3-" (String#4796, DoABC#2)
// _SafeStr_110 = "_-B0" (String#5184, DoABC#2)
// _SafeStr_111 = "_-V" (String#5280, DoABC#2)
// _SafeStr_112 = "_-3X" (String#4821, DoABC#2)
// _SafeStr_113 = "_-4L" (String#4857, DoABC#2)
// _SafeStr_114 = "_-2u" (String#4791, DoABC#2)
// _SafeStr_115 = "_-4T" (String#4861, DoABC#2)
// _SafeStr_116 = "_-1J" (String#4714, DoABC#2)
// _SafeStr_117 = "_-CQ" (String#5246, DoABC#2)
// _SafeStr_83 = "_-By" (String#5224, DoABC#2)
// _SafeStr_84 = "_-AL" (String#5149, DoABC#2)
// _SafeStr_85 = "_-CY" (String#5251, DoABC#2)
// _SafeStr_86 = "_-8Y" (String#5059, DoABC#2)
// _SafeStr_87 = "_-Bs" (String#5219, DoABC#2)
// _SafeStr_88 = "_-13" (String#4703, DoABC#2)
// _SafeStr_89 = "_-7r" (String#5026, DoABC#2)
// _SafeStr_90 = "_-2C" (String#4760, DoABC#2)
// _SafeStr_91 = "_-4M" (String#4858, DoABC#2)
// _SafeStr_92 = "_-8a" (String#5061, DoABC#2)
// _SafeStr_93 = "_-1j" (String#4736, DoABC#2)
// _SafeStr_94 = "_-Cj" (String#5260, DoABC#2)
// _SafeStr_95 = "_-5e" (String#4918, DoABC#2)
// _SafeStr_96 = "_-8v" (String#5077, DoABC#2)
// _SafeStr_97 = "_-1I" (String#4713, DoABC#2)
// _SafeStr_98 = "_-Bo" (String#5215, DoABC#2)
// _SafeStr_99 = "_-C1" (String#5228, DoABC#2)


